package com.example.mn_mvvm_demo.main;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.lib_cache.adapter.StoryAdapter;
import com.example.lib_cache.view_model.AFragmentViewModel;
import com.example.lib_common.base.BaseFragment;
import com.example.mn_mvvm_demo.R;
import com.example.mn_mvvm_demo.databinding.FragmentABinding;

public class AFragment extends BaseFragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         super.onCreateView(inflater, container, savedInstanceState);
        FragmentABinding fragmentABinding=
                DataBindingUtil.inflate(
                        inflater,
                        getLayoutResourceId(),
                        container,false);

        AFragmentViewModel aFragmentViewModel=new AFragmentViewModel();

        RecyclerView recyclerView=fragmentABinding.recycler;
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext(),
                LinearLayoutManager.VERTICAL,false));

        StoryAdapter adapter=new StoryAdapter(
                aFragmentViewModel.getStoriesLiveData().getValue()
        );
        recyclerView.setAdapter(adapter);

        return fragmentABinding.getRoot();
    }

    @Override
    protected int getLayoutResourceId() {
        return R.layout.fragment_a;
    }

    @Override
    protected void initView() {

    }
}
